﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using GranitePackageSystem.GranitePackagingService;
using GranitePackageSystem.Controls;
namespace GranitePackageSystem.Views.Packaging.ChildWindows
{
    public partial class UploadFiles : ChildWindow
    {
        private int reqNumber;
        System.Windows.Controls.BusyIndicator busyIndicator = new System.Windows.Controls.BusyIndicator();
        public UploadFiles(int reqNumber)
        {
            this.reqNumber = reqNumber;
            InitializeComponent();
        }

        void Files_SingleFileUploadFinished(object sender, FileUploader.FileUploadedEventArgs e)
        {
            GranitePackagingServiceSoapClient proxy = new GranitePackagingServiceSoapClient();
            proxy.processFileCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(proxy_processFileCompleted);
            proxy.processFileAsync(e.FileGuid, e.FileName, this.reqNumber.ToString());

            this.busyIndicator.IsBusy = true;
        }

        void proxy_processFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            this.busyIndicator.IsBusy = false;
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void fileUploader_Loaded(object sender, RoutedEventArgs e)
        {
            this.fileUploader.Files.SingleFileUploadFinished += new EventHandler<FileUploader.FileUploadedEventArgs>(Files_SingleFileUploadFinished);
        }
    }
}

